num = input()
if len(num)==4:
  n1 = num[0]
  n2 = num[1]
  n3 = num[2]
  n4 = num[3]
  sp = [int(n1), int(n1 + n2), int(n1 + n2 + n3), int(n2), int(n2 + n3),int(n2 + n3 + n4), int(n3), int(n3 + n4), int(n4), int(num)]
  sp.sort()
  sp = sp[::-1]
  for d in sp:
    F = 1
    for a in range (2, d // 2 + 1):
      if d % a == 0:
        F = 0
        break
    if F == 1:
      print (d)
      break
  if F == 0:
    print (0)
else:
  print (0)
